package com.zijing2333.adaptivescheduling.SwitcherManager;

import android.util.Log;

import com.zijing2333.adaptivescheduling.criticalNodeJudgment.JudgeKeyNode;
import com.zijing2333.adaptivescheduling.criticalNodeJudgment.JudgeKeyNode1;
import com.zijing2333.servicerunner.JSStatus;
import com.zijing2333.servicerunner.TaskInfo;

public class SwitchTaskInfo {
    private static final String TAG = "fun_SwitchTaskInfo";
    private String taskId;//任务id
    private String url;//代码地址
    private boolean isFrontendRequired;//是否需要前端
    private int priority;
    private boolean isKeyNode = false;//是否为关键节点

    private boolean deployed = false;//任务是在对端设备上的副本任务是否部署

    private JSStatus state;//任务状态,包括running,

    private String sourceIP; //该属性针是副本任务特有的，标记源设备的IP地址

    private int SocketEstablishType = 0; //SocketEstablishType==0 表示任务未建立Socket，==1表示任务建立的是客户端Socket，===2表示任务建立的是服务端socket
    private String taskParams;

    //构造函数
    public SwitchTaskInfo(String taskId, String url, boolean isFrontendRequired, int priority){
        this.taskId = taskId;
        this.url = url;
        this.isFrontendRequired = isFrontendRequired;
        this.priority = priority;
        this.state = JSStatus.CODE_NOT_DOWNLOADED;
        this.isKeyNode = JudgeKeyNode1.getInstance().judge(priority);
        this.taskParams = "";
    }
//    public SwitchTaskInfo(TaskInfo taskInfo){
//        this.taskId = taskInfo.getTaskId();
//        this.isFrontendRequired = taskInfo.isFrontendRequired();
//        this.taskParams = taskInfo.getTaskParams();
//        /**资源视图中为Tasktype类型,以后可能会修改
//         * */
////        String[] type = taskInfo.getTasktype().split("-");
////        if("front".equals(type[1])){
////            this.isFrontendRequired = true;
////        }else{
////            this.isFrontendRequired = false;
////        }
//        this.state = "PENDING";
//        this.isKeyNode = JudgeKeyNode.judge(this.priority);
//    }
    //返回原始的TaskInfo类
    public TaskInfo getTaskInfo(){
        TaskInfo taskInfo = new TaskInfo(this.taskId,this.isFrontendRequired,this.taskParams);
        return taskInfo;
    }

    //设置socket建立的类型，type=0表示该任务未建立socket，=1表示任务建立在客户端socket上，=2表示任务建立在服务端socket上
    public void setSocketEstablishType(int type) {
        SocketEstablishType = type;
    }
    //得到socket建立的类型
    public int getSocketEstablishType() {
        return SocketEstablishType;
    }


    //设置副本任务的sourceIp属性
    public void setSourceIP(String sourceIP) {
        this.sourceIP = sourceIP;
    }
    //得到副本任务的sourceIp属性
    public String getSourceIP() {
        return sourceIP;
    }


    //查看对端设备上的副本任务是否处于预部署状态，等待启动
    public boolean isDeployed() {
        return deployed;
    }
    //设置对端设备上的副本任务处于预部署状态，等待启动
    public void setDeployed(boolean deployed) {
        this.deployed = deployed;
    }

    //设置任务ID
    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }
    //得到任务ID
    public String getTaskId() {
        return taskId;
    }

    //得到任务的URL
    public String getUrl() {
        return url;
    }
    //设置任务的url
    public void setUrl(String url) {
        this.url = url;
    }

    //设置任务是否是前端任务
    public void setFrontendRequired(boolean frontendRequired) {
        isFrontendRequired = frontendRequired;
    }
    //得到任务是否是前端任务
    public boolean getIsFrontendRequired() {
        return isFrontendRequired;
    }

    //得到任务是否是关键节点
    public boolean isKeyNode() {
        return isKeyNode;
    }
    //设置任务的关键节点属性
    public void setKeyNode(boolean keyNode) {
        isKeyNode = keyNode;
    }

    //得到任务状态
    public JSStatus getState() {
        return state;
    }
    //设置任务状态
    public void setState(JSStatus state) {
        this.state = state;
    }

    //得到任务优先级
    public int getPriority() {
        return priority;
    }
    //设置任务优先级
    public void setPriority(int priority) {
        this.priority = priority;
    }
}
